//
//  progressView.m
//  CALayer
//
//  Created by 楼楚 on 16/3/2.
//  Copyright © 2016年 Chu Lou. All rights reserved.
//

#import "progressView.h"
@interface progressView ()
@property (nonatomic,strong) CALayer *progressLayer;
@property (nonatomic,assign) CGFloat currentViewWidth;


@end
@implementation progressView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self) {
        self.progressLayer = [CALayer layer];
        
        self.progressLayer.frame = CGRectMake(0, 0, 0, frame.size.height);
        self.progressLayer.backgroundColor = [UIColor redColor].CGColor;
        [self.layer addSublayer:self.progressLayer];
        
        
        self.currentViewWidth = frame.size.width;
    }
    
    return self;
}
#pragma mark -setter getter
@synthesize progress = _progress;
- (void)setProgress:(CGFloat)progress
{
    _progress = progress;
    if (progress <= 0) {
        self.progressLayer.frame = CGRectMake(0, 0, 0, self.frame.size.height);
    }else if (progress <= 1){
        self.progressLayer.frame = CGRectMake(0, 0, progress*self.currentViewWidth, self.frame.size.height);
    }else{
        self.progressLayer.frame = CGRectMake(0, 0, self.currentViewWidth, self.frame.size.height);
    }
        
}

- (CGFloat)progress{
    return _progress;
}
@synthesize layerColor = _layerColor;
- (void)setLayerColor:(UIColor *)layerColor {
    _layerColor = layerColor;
    self.progressLayer.backgroundColor = layerColor.CGColor;
}
- (UIColor *)layerColor {
    return _layerColor;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
